package financial.sharing.center.payable.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import financial.sharing.center.common.enums.ResponseContext;
import financial.sharing.center.common.utils.PageSize;
import financial.sharing.center.common.utils.R;
import financial.sharing.center.payable.model.entity.PayableAccrued;
import financial.sharing.center.payable.service.PayableAccruedService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.Map;

/**
 * @ClassName PayableAccruedController
 * @Description TODO
 * @Author guoyuhang
 * @ @csdn https://blog.csdn.net/qq_40788718
 * @Date 2021/5/15
 * @Version 1.0
 */
@RestController
@RequestMapping(value = "/payable/payable/accrued/")
public class PayableAccruedController {

    @Autowired
    private PayableAccruedService payableAccruedServiceImpl;

    @PostMapping(value = "get/all/payable/accrued")
    public R getAllPayableAccrued(Integer accruedId,
                                  Integer contractId,
                                  Integer currentPage){
        PageHelper.startPage(currentPage, PageSize.PAGESIZE_TEN);
        PageInfo<PayableAccrued> result = this.payableAccruedServiceImpl.getAllPayableAccrued(contractId, accruedId);
        return R.ok(result);
    }

    @PostMapping(value = "create/one/payable/accrued")
    public R createOnePayableAccrued(BigDecimal settlementAmount){
        Integer result = this.payableAccruedServiceImpl.createOnePayableAccrued(settlementAmount);
        return R.ok(ResponseContext.int2Enum(result).getName());
    }

    @PostMapping(value = "compile/one/payable/accrued")
    public R compileOnePayableAccrued(@RequestBody PayableAccrued payableAccrued){
        Integer result = this.payableAccruedServiceImpl.compileOnePayableAccrued(payableAccrued);
        return R.ok(ResponseContext.int2Enum(result).getName());
    }

    @PostMapping(value = "delete/one/payable/accrued")
    public R deleteOnePayableAccrued(Integer id){
        Integer result = this.payableAccruedServiceImpl.deleteOnePayableAccrued(id);
        return R.ok(ResponseContext.int2Enum(result).getName());
    }

    @PostMapping(value = "get/map/payable/accrued")
    public Map<Integer,BigDecimal> getMapPayableAccrued(){
        return this.payableAccruedServiceImpl.getMapPayableAccrued();
    }
}
